package ledrpt

import org.kdx.DateUtils

import java.text.SimpleDateFormat

class StepInOutPutController {
    def dynamicQueryService

    def stepInOutPut() {
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()-30))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date().clearTime()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def dayList = DateUtils.getHourList(startTime, endTime)


        params.SYS_QUERY_NAME = 'packageForm'
        def packageForm = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut'
        def stepInOutPut = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut1'
        def stepInOutPut1 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut2'
        def stepInOutPut2 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut3'
        def stepInOutPut3 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut4'
        def stepInOutPut4 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut5'
        def stepInOutPut5 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut6'
        def stepInOutPut6 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut8'
        def stepInOutPut8 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut9'
        def stepInOutPut9 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut10'
        def stepInOutPut10 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut11'
        def stepInOutPut11 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut7'
        def stepInOutPut7 = dynamicQueryService.queryForList(params)
        [startTime    : startTime, endTime: endTime,
         stepInOutPut : stepInOutPut, stepInOutPut1: stepInOutPut1, stepInOutPut2: stepInOutPut2,
         packageForm  : packageForm,
         stepInOutPut4: stepInOutPut4,
         stepInOutPut5: stepInOutPut5,
         stepInOutPut3: stepInOutPut3,
         stepInOutPut6: stepInOutPut6,
         stepInOutPut8:stepInOutPut8,
         stepInOutPut9:stepInOutPut9,
         stepInOutPut10:stepInOutPut10,
         stepInOutPut11:stepInOutPut11,
         stepInOutPut7:stepInOutPut7,
         RESERVED1    : params.RESERVED1]
    }

    def exportExcel() {
        def sysQueryName
        sysQueryName = params.SYS_QUERY_NAME

        params.startNo = 1
        params.endNo = 99999999999999999
        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = sysQueryName

        def dataList = dynamicQueryService.queryForList(params)

        def tableHeadList = []
        if (dataList.size() > 0) {
            tableHeadList = dataList[0].keySet()
        }
        def stepInOutPut


        params.SYS_QUERY_NAME = 'stepInOutPut'
        stepInOutPut = dynamicQueryService.queryForList(params)

        params.SYS_QUERY_NAME = 'packageForm'
        def packageForm = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut1'
        def stepInOutPut1 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut2'
        def stepInOutPut2 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut3'
        def stepInOutPut3 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut4'
        def stepInOutPut4 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut5'
        def stepInOutPut5 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut6'
        def stepInOutPut6 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut8'
        def stepInOutPut8 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut9'
        def stepInOutPut9 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut10'
        def stepInOutPut10 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut11'
        def stepInOutPut11 = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepInOutPut7'
        def stepInOutPut7 = dynamicQueryService.queryForList(params)



        String filename = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}",
                model: [dataList: dataList, tableHeadList: tableHeadList,
                        packageForm:packageForm,
                        stepInOutPut1:stepInOutPut1,
                        stepInOutPut2:stepInOutPut2,
                        stepInOutPut3:stepInOutPut3,
                        stepInOutPut5:stepInOutPut5,
                        stepInOutPut4:stepInOutPut4,

                        stepInOutPut6:stepInOutPut6,
                        stepInOutPut7:stepInOutPut7,

                        stepInOutPut8:stepInOutPut8,
                        stepInOutPut9:stepInOutPut9,
                        stepInOutPut10:stepInOutPut10,
                        stepInOutPut11:stepInOutPut11,
                        stepInOutPut: stepInOutPut])
    }
}
